<template>
    <!--导航栏部分-->
<div class="sidenav">
    <div style="height:50px"></div>
   <router-link  to="/SelfInfo"> <div class="AvatarBox">
        <img src="../assets/resource/avatar.png">
        </div>
    </router-link>
        <div class="NameBox">
        <div>Administrator</div>
        </div>
    <div style="height:50px"></div>
    <router-link to="/AddUser"><div class="NavItems">Adduser</div></router-link>
    <router-link to="/Management"><div class="NavItems">Management</div></router-link>
    <router-link to="/Role"><div class="NavItems">RoleManagement</div></router-link>
   <div class="NavItems" @click="logout()">Logout</div>
      </div>
    <!--页面主体-->
    <div class="main">
        <div class="Head">
	<div class="HeadPrompt">SelfInfo</div>
</div>
<div style="height: 50px;px;width:100% "></div>
<div class="InputBox">
    <br>
	<div class="InputBoxTitle">SelfInfo</div>
    <br>
    <div class="InnerBox">
    <div class="InnerBox2">
    <div class="HintBox">
	<div>Username:</div>
	</div>
	<input class="inputText" type="text" id="UserName">
    <br>
	<div class="HintBox">
	<div>StudentId:</div>
	</div>
	<input class="inputText" type="text" id="StudentId">
    <br>
	<div class="HintBox">
	<div>Mobile:</div>
	</div>
	<input class="inputText" type="text" id="PhoneNumber" >
    <br>
    </div>
    <div class="InnerBox2">
        
	<div class="HintBox">
	<div>Password:</div>
	</div>
	<input class="inputText" type="text" id="PassWord">
    <br>
	<div class="HintBox">
	<div>Region:</div>
	</div>
	<input class="inputText" type="text"  id="Region">
    <br>
	<div class="HintBox">
	<div>E-mail:</div>
	</div>
	<input class="inputText" type="text" id="Email">
    <br>
    </div>

    </div>

    <input type="button"   class="button_Class" @click="AddUser()" value="ADD">





    </div>

  

    </div>
</template>

<script>

import axios  from 'axios';
export default {

data(){
  return{
    AddUserInfo:{
      UserName:"",
      PassWord:"",
      StudentId:"",
      Email:"",
      PhoneNumber:"",
      Region:""

    },
     }
},
 
methods:{
 AddUser(){
    this.AddUserInfo.UserName=document.getElementById("UserName").value;
    this.AddUserInfo.PassWord=document.getElementById("PassWord").value;
    this.AddUserInfo.StudentId=document.getElementById("StudentId").value;
    this.AddUserInfo.Email=document.getElementById("Email").value;
    this.AddUserInfo.PhoneNumber=document.getElementById("PhoneNumber").value;
    this.AddUserInfo.Region=document.getElementById("Region").value;
    if(this.AddUserInfo.UserName==""||this.AddUserInfo.PassWord==""||this.AddUserInfo.StudentId==""||this.AddUserInfo.Email==""||this.AddUserInfo.PhoneNumber==""||this.AddUserInfo.Region==""){
     alert("请完善信息");
     return;
    }
    const obj = {
			UserName:this.AddUserInfo.UserName,
	        PassWord:this.AddUserInfo.PassWord,
	        Email:this.AddUserInfo.Email,
	        PhoneNumber:this.AddUserInfo.PhoneNumber,
	        StudentId:this.AddUserInfo.StudentId,
	        Region:this.AddUserInfo.Region
		}
    axios.post('/api/user/AddUser',obj,{
	headers: {
        'Content-Type': 'application/json',
		'_accessToken_': localStorage.getItem("accessToken")
	}
})
.then( (result) => {
	if(result.data.success){
        alert("添加用户成功");
        return;
    }
    else{
        alert(result.data.msg);
        return;
    }
})
.catch( (err) => {
	console.log('报错提示', err)
})    

  },
logout(){
    if(confirm("确定退出登录？")){
        axios.get('/api/auth/logout',{
            headers: {
                '_accessToken_': localStorage.getItem("accessToken")
            }
                
        } 
  ).then((result) => {
            if(result.data.success){
                localStorage.removeItem("accessToken");
                this.$router.replace('/Login');
                return;
            }
            else{
             alert(result.data.msg);
             return;
            }
      
              
          });

}
},


},
mounted(){

}}

</script>

<style lang="less">
@import "@/assets/word-like.less";
@import "@/assets/paper.less";
@import "@/assets/CSS/Nav.css";
@import "@/assets/CSS/Adduser.css";


</style>